<?php 
require('check_init.php'); 
?>
<h1> <?php echo _XG_NETPBM01;?> </h1>
<?php echo _XG_NETPBM02;?> <?php echo _XG_NETPBM03;?> 
<?php echo _XG_NETPBM04;?><p><ol>
<p><li><?php echo _XG_NETPBM05;?>
<p><?php echo _XG_NETPBM06;?><br><b><?php passthru("uname -a"); ?></b>
<p><?php echo _XG_NETPBM07;?><br><b><?php echo php_uname() ?></b>
<p><?php echo _XG_NETPBM08;?><p>
<?php echo _XG_NETPBM09;?> <?php echo _XG_NETPBM10;?> 
<?php echo _XG_NETPBM11;?> 
<a href="http://www.netcraft.com/whats?host=<?php echo $_SERVER['HTTP_HOST']?>"><?php echo _XG_NETPBM13;?></a><?php echo _XG_NETPBM12;?><p>
<li><?php echo _XG_NETPBM14;?><p><ul><b><?php echo $gallery->app->pnmDir ?></b></ul><p>
<?php echo _XG_NETPBM15;?><p><?php $debugfile = tempnam($gallery->app->tmpDir, "gallerydbg");?>
<?php
if (!inOpenBasedir($gallery->app->pnmDir)) {
?>
<?php echo _XG_NETPBM16;?> <?php echo _XG_NETPBM17;?><?php echo $gallery->app->pnmDir ?><?php echo _XG_NETPBM18;?><ul>
<?php echo join('<br>', explode(':', ini_get('open_basedir'))) ?></ul>
<?php echo _XG_NETPBM34;?><br><br>
<?php
}
?>
<li><?php echo _XG_NETPBM35;?>
<?php
if ($show_details) {
	print "<a href=\"index.php?op=check_netpbm&amp;show_details=0\">"._XG_NETPBM47."</a> "._XG_NETPBM48."</a>";
} else {
	print _XG_NETPBM49." <a href=\"index.php?op=check_netpbm&amp;show_details=1\">"._XG_NETPBM47."</a> "._XG_NETPBM50."</a>";
}
?>

<pre>
<?php
$binaries = array("giftopnm",
		  "jpegtopnm",
		  "pngtopnm",
		  "pnmcut",
		  "pnmfile",
		  "pnmflip",
		  "pnmrotate",
		  "pnmscale",
		  "pnmtopng",
		  "ppmquant",
		  "ppmtogif",
		  $gallery->app->pnmtojpeg,
	    );
		
	// Note:  ppmquant is obsolete as of v10.19 may show error
	// Unknown Option: version
	// pmnquant (ppmquant's replacement) may also show same error

foreach ($binaries as $bin) {
	checkNetPbm($bin, $gallery, $show_details, $debugfile);
}

if (fs_file_exists($debugfile)) {
    fs_unlink($debugfile);
}

function checkNetPbm($cmd, $gallery, $show_details, $debugfile) {

	$cmd = fs_executable($gallery->app->pnmDir . "/$cmd");
	print _XG_NETPBM19. fs_import_filename($cmd) ."\n";

	$ok = 1;

	if ($ok) {
		if (inOpenBasedir($gallery->app->pnmDir)) {
			if (!fs_file_exists($cmd)) {
				$error = sprintf(_XG_NETPBM20, $cmd);
				$ok = 0;
			}
		}
	}

	$cmd .= _XG_NETPBM26;
		
	fs_exec($cmd, $results, $status, $debugfile);

	if ($ok) {
		if ($status != $gallery->app->expectedExecStatus) {
			$error = _XG_NETPBM24 .
				$gallery->app->expectedExecStatus .
				_XG_NETPBM25." $status";
			$ok = 0;
		}
	}

	/*
	 * Windows does not appear to allow us to redirect STDERR output, which
	 * means that we can't detect the version number.
	 */
	if ($ok) {
	    if (substr(PHP_OS, 0, 3) == 'WIN') {
		$version = "<i>"._XG_NETPBM23."</i>";
	    } else {
		if ($fd = fopen($debugfile, "r")) {
		    $linecount = 0;
		    $version = null;
		    while (!feof($fd)) {
				$linecount++;
				$buf = fgets($fd, 4096);
				if ($linecount == 1) {
				    if (eregi("using libn?e?t?pbm from netpbm version: netpbm (.*)[\n\r]$", 
					      $buf, $regs)) {
						$version = $regs[1];
				    } else {
						$error = $buf;
						$ok = 0;
				    }
				}
				if ($show_details) {
				    print $buf;
				}
		    }
		    fclose($fd);
		}
	    }
	}

	if ($ok) {
		print "<font color=green>"._XG_NETPBM22." $version</font>";
	} else {
		print "<font color=red>"._XG_NETPBM21." ($error) </font>";
	}
	print "\n\n";
}

function inOpenBasedir($dir) {
    $openBasedir = ini_get('open_basedir');
    if (empty($openBasedir)) {
	return true;
    }

    return in_array($dir, explode(':', $openBasedir));
}
    
?>
</pre>

<p>
<?php echo _XG_NETPBM37;?> <b><?php echo $debugfile?></b><?php echo _XG_NETPBM38;?> <?php echo _XG_NETPBM39;?> <a
href="http://www.php.net/manual/en/configuration.php#ini.open-basedir">
<?php echo _XG_NETPBM40;?></a> <?php echo _XG_NETPBM41;?> <?php echo _XG_NETPBM42;?> 
<a href="http://gallery.sourceforge.net/help.php"><?php echo _XG_NETPBM43;?></a>
<p><?php echo _XG_NETPBM44;?> <a href="http://gallery.sourceforge.net/faq.php"><?php echo _XG_NETPBM45;?></a> 4.4 <?php echo _XG_NETPBM46;?></ol>